package com.wy.service.impl;

import com.wy.dao.UserDao;
import com.wy.pojo.User;
import com.wy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * description UserServiceImpl
 * author wy
 * date 2021-09-01 22:05
 **/
@Service
public class UserServiceImpl implements UserService
{
    @Autowired
    private UserDao userDao;

    @Override
    public User getUserByEmail(String email)
    {
        User user = new User();
        user.setEmail(email);
        Example<User> example = Example.of(user);
        if (userDao.findOne(example).isPresent()) {
            return userDao.findOne(example).get();
        }
        return null;
    }

    @Override
    @Transactional
    public void addUser(User user)
    {
        userDao.saveAndFlush(user);
    }
}
